package dp.mobile.game;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class ScoreCollection implements Serializable {
	public ScoreCollection(){
		mHighScores = new ArrayList<Score>();
	}
	
	public void addScore(Score newScore){
		mHighScores.add(newScore);
	}
	
	public void sortAllScores(){
		Collections.sort(mHighScores, new ScoreComparator());
		if(mHighScores.size() > MAX_SCORE_SAVED)
			mHighScores.remove(mHighScores.size() - 1);
	}
	
	//Accessors
	public ArrayList<Score> getHighScores(){
		return mHighScores;
	}
	
	//ATTRIBUTES
	private static final long serialVersionUID = -3270922555448711285L;
	public static final int MAX_SCORE_SAVED	= 5;
	private ArrayList<Score> mHighScores;
	
	public class ScoreComparator implements Comparator<Score>{
	    public int compare(Score emp1, Score emp2){
	        int score1Score = emp1.getScoreValue();        
	        int score2Score = emp2.getScoreValue();
	       
	        if(score1Score < score2Score)
	            return 1;
	        else if(score1Score > score2Score)
	            return -1;
	        else
	            return 0;    
	    }
	}
}
